<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Generator</title>
</head>

<body>
    <script>
        // function* request() {
        //     yield "pedding";
        //     console.log("执行中");
        //     yield "loading"
        //     return "fullfilled";
        // }

        // var req = request();


        // // // // console.log(req[Symbol.iterator]() == req);
        // // while(req.next().done == false){
        // //     console.log(req.next());
        // // }
        // for (let v of req) {
        //     console.log(v);
        // }
        // console.log(req.next());
        // // console.log(req.next());

        // function* foo(x) {
        //     var y = 2 * (yield (x + 1));
        //     console.log(y);
        //     var z = yield (y / 3);
        //     console.log(x,y,z);
        //     return (x + y + z);
        // }

        // var a = foo(5);
        // console.log(a.next());
        // console.log(a.next(6));
        // console.log(a.next(4));


        //封装方法可迭代的对象
        function* iterEntries(obj){
            let keys = Object.keys(obj);

            for(let i=0;i<keys.length;i++){
                let key = keys[i];
                yield [key,obj[key]];
            }
        }

        let objs = {foo:3,name:4,age:5};

        for(let [k,v] of iterEntries(objs)){
            console.log(k,v);
        }


        let property = {};
        Object.defineProperty(property,"name",{
            // value:"张三",
            get(){
                return "张三"
            },
            // writable:false,
            set(val){
                console.log(val,"xxxx");
            }
        })

        property.name = "李四";

        console.log(Object.getOwnPropertyDescriptors(property));//查看对象属性
    </script>
</body>

</html>